/**
 * 修改附加物品数据接口
 */

//引入Q模块
var Q = require('q');
//引入公共函数
var util = require('../../util');

//editGoods接口入口文件
var index = function(getData, postData, config, _redis, db) {
	let deferred = Q.defer();
	if(postData.goodsId && postData.goodsName && postData.goodsPrice && postData.goodsCount) {
		db.update('attachGoods', {
			goodsId: postData.goodsId
		}, {
			goodsName: postData.goodsName,
			goodsPrice: postData.goodsPrice * 100,
			goodsCount: postData.goodsCount,
			goodsForce: (postData.goodsForce == 0 ? false : true),
			goodsChecked: (postData.goodsChecked == 0 ? false : true),
			timestamp: Date.now()
		}).then(function() {
			deferred.resolve({
				timestamp: Date.now()
			});
		}, function() {
			//更改附加物品数据失败
			deferred.reject('-0185');
		});
	}
	else {
		//修改附加物品接口参数不足
		deferred.reject('-0184');
	}
	return deferred.promise;
}

//暴露接口
module.exports = {
	index: index
}